package top.itaso.app.ui.btn

import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Switch
import android.widget.TextView
import androidx.annotation.RequiresApi
import androidx.fragment.app.Fragment
import top.itaso.app.R
import top.itaso.lib.common.StorageVolumeUtils

/**
 * @Description:
 * @Author dengfu.su
 * @Date 2023/2/16
 */
class ButtonsFragment : Fragment() {
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val rootView = inflater.inflate(R.layout.fragment_button_status, container, false)
        setupView(rootView)
        return rootView
    }

    private fun setupView(rootView: View) {
        var btnStatusEnabled: TextView = rootView.findViewById(R.id.btn_status_enable)
        var switchBtnEnabled: Switch = rootView.findViewById(R.id.switch_btn_enabled)
        switchBtnEnabled.isChecked = btnStatusEnabled.isEnabled
        switchBtnEnabled.setOnCheckedChangeListener { _, isChecked ->
            btnStatusEnabled.isEnabled = isChecked
        }
        btnStatusEnabled.setOnClickListener(object : View.OnClickListener {
            @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
            override fun onClick(v: View?) {
//                FileUtils.readLineFromFile(FileUtils.getInnerSDPath(context) + File.separator + "version.txt")
//               FileUtils.readLineFromFile("/storage/sda1/version.txt")
//                StorageUtils.getUsbDrivePath(context)
//                StorageUtils.getUsbDevices(context)
//                StorageVolumeUtils.getVolumes(context)
//                StorageVolumeUtils.getAppPrivateDir(context)
//                StorageVolumeUtils.getStorageVolumes(context)
//                StorageVolumeUtils.getUsbDeviceList(context)
                StorageVolumeUtils.getVolumes(context)
            }

        })


        var btnStatusSelected: TextView = rootView.findViewById(R.id.btn_status_selected)
        var switchBtnSelected: Switch = rootView.findViewById(R.id.switch_btn_selected)
        switchBtnSelected.isChecked = btnStatusSelected.isSelected
        switchBtnSelected.setOnCheckedChangeListener { _, isChecked ->
            btnStatusSelected.isSelected = isChecked
        }


        var btnStatusFocused: TextView = rootView.findViewById(R.id.btn_status_focused)
        btnStatusFocused.isFocusableInTouchMode = true
        btnStatusFocused.requestFocusFromTouch()
        btnStatusFocused.requestFocus()


        rootView.findViewById<View>(R.id.layout_item_stauts_normal).setOnClickListener(null)

        var layoutItemDisabled: View = rootView.findViewById(R.id.layout_item_stauts_disabled)
        layoutItemDisabled.isEnabled = false

        var layoutItemSelected = rootView.findViewById<View>(R.id.layout_item_stauts_selected)
        layoutItemSelected.isSelected = true
        layoutItemSelected.setOnClickListener(null)

    }


    companion object {
        private const val TAG = "SelectorStatusFragment"
    }
}